package com.trkj.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.AttendanceDAO;
import com.trkj.dao.EmpDAO;
import com.trkj.pojo.Emp;

@Service
@Transactional
public class CountAttendanceService {
	@Autowired
	AttendanceDAO attendanceDAO;
	@Autowired
	EmpDAO empDAO;
	
	public List<Map<String, Object>> countAttendanceInfo(Integer empId) {
		List<Object[]> list = null;
		List<Map<String, Object>> list2 = new ArrayList<>();
		if (empId==null) {
			list = attendanceDAO.CountAttendance();
		}else {
			list = attendanceDAO.CountAttendanceAnd(empId);
			
		}
		for (Object[] objects : list) {
			Map<String, Object> map = new HashMap<>();
			map.put("name", objects[0]);
			map.put("value", objects[1]);
			list2.add(map);
		}
		return list2;
	}
	
	
	/**
	 * 查询员工表中的记录
	 * @author csj
	 * @return
	 */
	public List<Map<String, Object>> findAll_emp_combobox() {
		List<Emp> findAll	= empDAO.findAll();
		List<Map<String, Object>> listmap = new ArrayList<>();
		if (findAll!=null) {
			for (Emp emp : findAll) {
				Map<String, Object> map = new HashMap<>();
				map.put("empId", emp.getEmpId());
				map.put("empName", emp.getEmpName());
				listmap.add(map);
			}
		}
		return listmap;
	}
	
	
	public Map<String, List<Object>> findCountdeptEmpInfo() {
		Map<String, List<Object>> outmap = new HashMap<>();
		List<Object[]> list = attendanceDAO.countDeptemp();
		List<Object> names = new ArrayList<>();
		List<Object> values = new ArrayList<>();
		for (Object[] objects : list) {
			names.add(objects[0]);
			values.add(objects[1]);
		}
		outmap.put("names", names);
		outmap.put("values", values);
		return outmap;
	}
}
